package com.example.demo.service;

import com.example.demo.dao.staffMapper;
import com.example.demo.pojo.Staff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StaffService {
    @Autowired
    staffMapper staffmapper;

    @Transactional(timeout = 10, readOnly = true, rollbackFor = Exception.class)
    public List<Staff> selectAllStaffs() {
        return staffmapper.selectAllStaffs();
    }

    @Transactional(timeout = 10, readOnly = true, rollbackFor = Exception.class)
    public Staff selectStaffByusername(String username){
        return staffmapper.selectStaffByusername(username);
    }

    @Transactional(timeout = 10, rollbackFor = Exception.class)
    public Staff selectStaffById(int id){
        return staffmapper.selectStaffById(id);
    }

    @Transactional(timeout = 10, rollbackFor = Exception.class)
    public void addStaff(Staff staff){
        staffmapper.addStaff(staff);
    }

    @Transactional(timeout = 10, rollbackFor = Exception.class)
    public void updateStaff(Staff staff){
        staffmapper.updateStaff(staff);
    }

    @Transactional(timeout = 10, rollbackFor = Exception.class)
    public void deleteStaff(int id){
        staffmapper.deleteStaff(id);
    }

    @Transactional(timeout = 10, rollbackFor = Exception.class)
    public void changeAllStaffs(List<Staff> staff){
        for(Staff staff1:staff){
            staffmapper.updateStaff(staff1);
        }
    }

    @Transactional(timeout = 10, readOnly = true, rollbackFor = Exception.class)
    public int staff_num(){
        return staffmapper.staff_num();
    }


}
